package com.ytjj.qmyx.admin.controller;


import com.ytjj.common.api.CommonPage;
import com.ytjj.common.api.CommonResult;
import com.ytjj.common.api.ResultCode;
import com.ytjj.qmyx.admin.annotation.OperLog;
import com.ytjj.qmyx.admin.constants.SysLogConstants;
import com.ytjj.qmyx.admin.model.request.ProductSelectRequest;
import com.ytjj.qmyx.admin.model.request.SelectRequest;
import com.ytjj.qmyx.admin.model.request.SelectSpecRequest;
import com.ytjj.qmyx.admin.model.response.SelectResponse;
import com.ytjj.qmyx.admin.service.ProductSelectService;
import com.ytjj.qmyx.mall.model.ProductSelectSpec;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/productSelect")
public class ProductSelectController {
    @Resource
    private ProductSelectService productSelectService;

    /**
     * 查看已被选品的商品列表
     */
    @PostMapping("/selectSelectList")
    public CommonResult selectSelectList(@RequestBody SelectRequest selectRequest) {
        CommonPage<SelectResponse> pageList = productSelectService.selectSelectList(selectRequest);
        return CommonResult.success(pageList);
    }

    /**
     * 修改接单状态
     */
    @PostMapping("/updateReceStatus")
    @OperLog(operModule = "接单模块", operDesc = "修改接单状态", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult updateReceStatus(@RequestBody ProductSelectRequest productSelectRequest) {
        int count = productSelectService.updateReceStatus(productSelectRequest);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * @Description 补全商品信息
     *
     *
     *
     * @Version 1.0
     **/
    @PostMapping("/completeSelectProductInfo")
    @OperLog(operModule = "选品商品模块", operDesc = "补全商品信息", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult completeSelectProductInfo(@RequestBody ProductSelectRequest productSelectRequest) {
        int count = productSelectService.completeSelectProductInfo(productSelectRequest);
        if(count > 0) {
            return CommonResult.success(ResultCode.SUCCESS);
        }
        return CommonResult.success(ResultCode.FAILED);
    }



    /**
     * 规格列表
     */
    @PostMapping("/selectSpecList")
    public CommonResult selectSpecList(@RequestBody SelectSpecRequest selectSpecRequest) {
        CommonPage<ProductSelectSpec> pageList = productSelectService.selectSpecList(selectSpecRequest);
        return CommonResult.success(pageList);
    }
    /**
     * 编辑规格
     */
    @PostMapping("/updateSpec")
    @OperLog(operModule = "选品商品模块", operDesc = "编辑规格", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult updateSpec(@RequestBody ProductSelectSpec productSelectSpec){
        int count = productSelectService.updateSpec(productSelectSpec);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
    /**
     * 是否选品
     */
    @PostMapping("/updateSelectStatus")
    @OperLog(operModule = "选品商品模块", operDesc = "编辑选品状态", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult updateSelectStatus (@RequestBody ProductSelectRequest productSelectRequest){
        int count = productSelectService.updateSelectStatus(productSelectRequest);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
}
